home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d12 / cbibcode.arc / SETVBUF.C < prev    next >
Encoding:
C/C++ Source or Header  |  1991-08-05  |  560 b   |  25 lines

  1. /* setvbuf.c --- p 465 */
  2. #include <stdio.h>
  3. main()
  4. {
  5.     FILE *infile;
  6.     char filename[81], buffer[121];
  7.     printf("Enter name of a text file: ");
  8.     gets(filename);
  9.                     /* Open the file for reading */
  10.     if ( (infile = fopen(filename, "r")) == NULL)
  11.     {
  12.         printf("fopen failed.\n");
  13.         exit(0);
  14.     }
  15.                 /* Set up a new buffer for the file */
  16.     if (setvbuf(infile, buffer, _IOFBF, 120) != 0)
  17.         perror("setvbuf failed");
  18.     else
  19.     {
  20.         fgetc(infile);
  21.         buffer[120] = '\0';
  22.         printf("After reading one character buffer has:\n%s\n",
  23.                                 buffer);
  24.     }
  25. }